package com.tinama.jedis01.demo;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @author lgc
 * @createDate 2020/10/22 - 17:36
 */
public class SelectSort {
    public static void main(String[] args){
        int[] arr = {5,7,8,10,78,88,1};
        Arrays.stream(arr).sorted();

        ArrayList<Integer> arrayList = new ArrayList<Integer>();
        arrayList.add(-1);
        arrayList.add(3);
        arrayList.add(3);
        arrayList.add(-5);
        arrayList.add(7);
        arrayList.add(4);
        arrayList.add(-9);
        arrayList.add(-7);
        System.out.println("原始数据："+arrayList);
        arrayList.sort(null);
        Collections.sort(arrayList);
        System.out.println("排序数据："+arrayList);
        Collections.reverse(arrayList);
        System.out.println("倒序数据："+arrayList);
        Collections.sort(arrayList,(s1,s2)->s1.compareTo(s2));
        System.out.println("自定义排序数据："+arrayList);

        Collections.sort(arrayList,(s1,s2)->s2.compareTo(s1));
        System.out.println("自定义排序数据："+arrayList);
        Iterator<Integer> iterator = arrayList.iterator();


       /* while (iterator.hasNext()){
            Integer next = iterator.next();
            if (next%2==0){
                iterator.remove();
           }
        }
        System.out.println("arrayList = " + arrayList);*/

       /* List<Integer> collect = arrayList.stream().filter(s -> s % 2 == 0).collect(Collectors.toList());
        System.out.println("collect = " + collect);*/

       /* for (Integer integer : arrayList) {
            if (integer%2==0){
                arrayList.remove(integer);
            }
        }*/

        HashMap<String,Integer> hashMap = new HashMap();
        hashMap.put("1",6);
        hashMap.put("2",7);
        hashMap.put("3",8);
        hashMap.put("4",9);

        Iterator<Map.Entry<String, Integer>> iterator1 = hashMap.entrySet().iterator();
        while (iterator1.hasNext()){
            Map.Entry<String, Integer> next1 = iterator1.next();
            System.out.println("key:"+next1.getKey()+"=>"+next1.getValue());
        }

//        System.out.println(Arrays.toString(sort(arr)));
    }
    public static int[] sort(int arr[]){
        int temp;
        for (int i = 0; i < arr.length-1; i++) {
            //默认第0个为最小值 记录最小值
            int minIndex = i;
            for (int j = i+1; j < arr.length; j++) {
                if (arr[j]<arr[minIndex]){
                    minIndex = j;
                }
            }

            if (minIndex!=i){
                temp = arr[i];
                arr[i] = arr[minIndex];
                arr[minIndex] = temp;
            }
        }

        return arr;
    }
}
